<#include "/common/_header.html" />
<div class="page-group"><!-- 页面组 -->
	<div class="page page-current"><!-- 页面组中的每一个页面，可以互相跳转 -->
		<header class="bar bar-nav"><!-- 每个页面的头部 -->
			<h1 class="title">后台管理</h1>
		</header>
		<div class="content native-scroll"><!-- 每个页面的内容区域 -->
			<div class="content-block">
				<p><a href="#" class="button button-fill" onclick="updateMenu()">更新微信菜单</a></p>
				
				<p>
					<textarea id="msgContent" style="width:100%"></textarea>
				<p>
				<div class="row">
			      <div class="col-50"><a href="#" class="button button-fill" onclick="sendMsgPreview()">预览群发消息</a></div>
			      <!-- <div class="col-50"><a href="#" class="button button-fill button-danger" onclick="sendMsg()">群发消息</a></div> -->
			    </div>
			</div>
			<div class="content-block">
				<p>
					<a href="#" class="button button-fill" onclick="createScanCode()">生成商家二维码</a>
					<input id="sellerid" type="text">
				</p>
				<div>
					<img id="scanPic" src="">
				</div>
			</div>
		</div>
	</div>
</div>
<#include "/common/_footer.html" />
<script>
function updateMenu(){
	$.showIndicator();
	$.ajax({
		type:'post',
		url:'${path}/api/createMenu',
		data:{},
		success:function(data){
			$.alert(data);
			$.hideIndicator();
		},
		error:function(xhr,errorType , error) {
			console.log("sorry error\r\n");
		}
	});
}
function sendMsg(){
	if($("#msgContent").val()==""){
		$.toast("请输入消息内容");
		return;
	}
	$.showIndicator();
	$.ajax({
		type:'post',
		url:'${path}/admini/sendMsg',
		data:{"msgContent":$("#msgContent").val()},
		success:function(data){
			$.alert(data);
			$.hideIndicator();
		},
		error:function(xhr,errorType , error) {
			console.log("sorry error\r\n");
		}
	});
}
function sendMsgPreview(){
	if($("#msgContent").val()==""){
		$.toast("请输入消息内容");
		return;
	}
	$.showIndicator();
	$.ajax({
		type:'post',
		url:'${path}/admini/sendMsgPreview',
		data:{"msgContent":$("#msgContent").val()},
		success:function(data){
			$.alert(data);
			$.hideIndicator();
		},
		error:function(xhr,errorType , error) {
			console.log("sorry error\r\n");
		}
	});
}
function createScanCode(){
	if(isNaN($("#sellerid").val())){
		$.toast("请输入商家id，数字哦");
		return;
	}
	$.showIndicator();
	$.ajax({
		type:'post',
		url:'${path}/admini/getScanCodeForSeller',
		data:{"sellerid":$("#sellerid").val()},
		success:function(data){
			if(data=="ERROR"){
				$.alert("报错");	
			}else{
				$("#scanPic").attr("src",data);	
			}
			$.hideIndicator();
		},
		error:function(xhr,errorType , error) {
			console.log("sorry error\r\n");
		}
	});
}
</script>